/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package commonInfrastructure.system.session;

import commonInfrastructure.accountManagement.entity.EmployeeEntity;
import commonInfrastructure.accountManagement.session.EmployeeSessionBean;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import commonInfrastructure.system.entity.SystemParameterEntity;
import javax.ejb.EJB;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author ReinforceII
 */
@Stateless
@LocalBean
public class SystemSessionBean {

    @PersistenceContext
    private EntityManager em;
    @EJB
    EmployeeSessionBean employeeSessionBean;

    public SystemParameterEntity getSystemParameter() {
        SystemParameterEntity systemParameter = em.find(SystemParameterEntity.class, 1L);
        return systemParameter;
    }

    public EmployeeEntity getCurrentUser() {
        EmployeeEntity employee;
        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        Long userId = (Long) request.getSession().getAttribute("isLogin");
        employee = employeeSessionBean.getEmployeeById(userId);
        return employee;

    }
}
